
<!--
 * @Description: 缺陷信息新增/整改/审核
 * @Author: Liu Zhiwang
 * @Date: 2021-04-13 17:05:40
 * @LastEditTime: 2024-01-12 11:35:58
 * @LastEditors: zhangweili zhang_weili@uxsino.com
-->
<template>
  <div>
    <base-dialog
      class="dialog_box dialog-body-fieldset"
      width="980px"
      :visible.sync="dialog.visible"
      :title="dialog.title"
      :loading="dialog.loading"
      :disabled="dialog.disabled"
      :show-default-footer="false"
      :show-fullscreen-icon="false"
      @updateData="updateData"
      @open="beforeOpenDialog">
      <div v-loading="loading" class="data-form-box">
        <!-- <el-scrollbar ref="scrollbarData" class="data-form-scrollbar"> -->
        <el-form
          ref="dataForm"
          :model="dialog.form"
          :rules="rules"
          :disabled="dialog.disabled"
          label-width="140px">
          <fieldset>
            <legend>缺陷信息</legend>
            <el-row>
              <el-col :span="8">
                <el-form-item label="线路" prop="seclineId">
                  <select-tree
                    v-model="dialog.form.seclineId"
                    :options="dataList.seclineList"
                    node-click
                    :props="{ label: 'label', value: 'id', parent: 'parentId', children: 'children' }"
                    :disabled="dialog.form.inputAuditStatus === 2 ? true : false"
                    @selected="changeSeclineId" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="区间站场" prop="siteId">
                  <el-select
                    v-model="dialog.form.siteId"
                    clearable
                    :disabled="dialog.form.inputAuditStatus === 2 ? true : false"
                    @change="changeSiteId">
                    <el-option
                      v-for="(item, index) in dataList.siteList"
                      :key="`a${index}`"
                      :label="item.siteName"
                      :value="item.siteId" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="支柱号" prop="pillarNum">
                  <select-table
                    ref="pillarNum"
                    v-model="dialog.form.pillarNum"
                    :filter-form="selectTableModel.filterForm"
                    :filter-data="selectTableModel.filterData"
                    :default-data="dataList.pillarList"
                    :columns="selectTableModel.columns"
                    :total="selectTableModel.total"
                    :filter-fn="selectTableModel.filterFn"
                    :disabled="dialog.form.inputAuditStatus === 2 ? true : false"
                    @current-change="changePillarId"
                    @clear="clearPillarId" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col v-if="dialog.form.pillarNum" :span="24">
                <el-form-item label="支柱关联信息" prop="originCode">
                  （公里标：{{ formatRoad(dialog.form.roadMark) }}，行别：{{ dialog.form.directionName }}，隧道：{{ dialog.form.tunnelName }}，股道：{{ dialog.form.trackName }}，所属工区：{{ dialog.form.pillarDeptName }}）
                </el-form-item>
              </el-col>
            </el-row>

            <!-- 设备缺陷 -->
            <template>
              <el-row>
                <el-col :span="8">
                  <el-form-item label="设备类别">
                    <select-tree
                      v-model="dialog.form.deviceClassId"
                      :options="dataList.devClasssList"
                      node-click
                      :props="{ label: 'label', value: 'id', parent: 'parentId', children: 'children' }"
                      :disabled="dialog.form.inputAuditStatus === 2 ? true : false" />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="缺陷来源" prop="discoverSourceTypeId">
                    <el-select
                      v-model="dialog.form.discoverSourceTypeId"
                      :disabled="dialog.form.inputAuditStatus === 2 ? true : false"
                      clearable>
                      <el-option
                        v-for="(item, index) in dialog.dataList.sourceList"
                        :key="`b${index}`"
                        :label="item.sourceTypeName"
                        :value="item.sourceTypeId" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="缺陷类型" prop="defectTypeName">
                    <select-table
                      v-model="dialog.form.defectTypeName"
                      :filter-form="selectTableModelClassify.filterForm"
                      :filter-data="selectTableModelClassify.filterData"
                      :default-data="dataList.classifyList"
                      :columns="selectTableModelClassify.columns"
                      :total="selectTableModelClassify.total"
                      :filter-fn="selectTableModelClassify.filterFn"
                      :disabled="dialog.form.inputAuditStatus === 2 ? true : false"
                      @current-change="changeTableItemDefectType"
                      @clear="dialog.form.defectTypeName = '';dialog.form.defectTypeId = ''" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="8">
                  <el-form-item label="缺陷等级" prop="defectGradeName">
                    <select-table
                      v-model="dialog.form.defectGradeName"
                      :filter-form="selectTableModelGrade.filterForm"
                      :filter-data="selectTableModelGrade.filterData"
                      :default-data="dataList.gradeList"
                      :columns="selectTableModelGrade.columns"
                      :total="selectTableModelGrade.total"
                      :filter-fn="selectTableModelGrade.filterFn"
                      :disabled="dialog.form.inputAuditStatus === 2 ? true : false"
                      @current-change="changeTableItemGrade"
                      @clear="dialog.form.defectGradeName = '';dialog.form.defectGradeId = ''" />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="发现人" prop="discoverPerson">
                    <select-table-multiple
                      ref="discoverPerson"
                      value-key="staffId"
                      label-key="staffName"
                      table-value-key="staffId"
                      :data="dialog.form.discoverPersonList"
                      :filter-form="selectTableModelFindBy.filterForm"
                      :filter-data="selectTableModelFindBy.filterData"
                      :default-data="dataList.staffList"
                      :collapse-tags="false"
                      :columns="selectTableModelFindBy.columns"
                      :total="selectTableModelFindBy.total"
                      :filter-fn="selectTableModelFindBy.filterFn"
                      :disabled="dialog.form.inputAuditStatus === 2 ? true : false"
                      @selection-change="changeTableItemFindBy"
                      @clear="dialog.form.discoverPersonList = [];dialog.form.discoverPerson = '';dialog.form.discoverPersonIdList = [];dialog.form.discoverPersonId = ''" />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="发现日期" prop="discoverDate">
                    <el-date-picker
                      v-model="dialog.form.discoverDate"
                      :picker-options="pickerOptions"
                      value-format="yyyy-MM-dd"
                      :disabled="dialog.form.inputAuditStatus === 2 ? true : false"
                      @change="changeFindDate" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="8">
                  <el-form-item label="整改期限" prop="rectifTime" class="rectif-datetime">
                    <el-input
                      v-model="dialog.form.rectifTime"
                      placeholder=""
                      class="input-with-select"
                      :disabled="dialog.form.inputAuditStatus === 2 ? true : false">
                      <el-select slot="append" v-model="dialog.form.rectifTimeUnit" placeholder="单位" @change="changeRectifTimeUnit">
                        <el-option v-for="(item, index) in dataList.rectifTimeUnitList" :key="index" :label="item.itemName" :value="item.dictionaryId" />
                      </el-select>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="整改责任工区" prop="solveWorkareaId">
                    <el-select
                      v-model="dialog.form.solveWorkareaId"
                      :disabled="dialog.form.inputAuditStatus === 2 ? true : false"
                      clearable>
                      <el-option
                        v-for="item in dataList.deptList"
                        :key="item.id"
                        :label="item.deptName"
                        :value="item.deptId" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="整改状态" prop="status">
                    <el-select
                      v-model="dialog.form.status"
                      value-key="value"
                      :disabled="dialog.form.inputAuditStatus === 2 ? true : false"
                      clearable>
                      <el-option label="未销号" value="NO" />
                      <el-option label="已销号" value="YES" />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </template>
            <!-- 设备缺陷 -->

            <el-row>
              <el-col :span="24">
                <el-form-item label="问题描述" prop="defectInfoDesc">
                  <el-input
                    v-model="dialog.form.defectInfoDesc"
                    type="textarea"
                    :autosize="{ minRows: 4}"
                    maxlength="500"
                    :disabled="dialog.form.inputAuditStatus === 2 ? true : false" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="整改建议" prop="rectificationSuggestions">
                  <el-input
                    v-model="dialog.form.rectificationSuggestions"
                    type="textarea"
                    :autosize="{ minRows: 4}"
                    maxlength="500"
                    :disabled="dialog.form.inputAuditStatus === 2 ? true : false" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <!-- <el-col :span="24">
                <el-form-item label="杆号照片" prop="pillarImagesList">
                  <upload-file :model="fileModalPillarImages" @on-success="uploadSuccessPillarImages" />
                </el-form-item>
              </el-col> -->
              <el-col :span="24">
                <el-form-item label="缺陷照片" prop="defectImagesList">
                  <upload-file :model="fileModalDefectImages" @on-success="uploadSuccessDefectImages" />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset v-if="dialog.form.status === 'YES'">
            <legend>整改情况</legend>
            <el-row>
              <el-col :span="8">
                <el-form-item label="整改日期" prop="solveDatetime" :rules="dialog.form.status == 'YES' ? rules.solveDatetime : [{required: false}]">
                  <el-date-picker
                    v-model="dialog.form.solveDatetime"
                    :picker-options="pickerHandleDate"
                    value-format="yyyy-MM-dd" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="整改工区" prop="handleWorkareaId" :rules="dialog.form.status == 'YES' ? rules.handleWorkareaId : [{required: false}]">
                  <el-select v-model="dialog.form.handleWorkareaId" clearable>
                    <el-option
                      v-for="item in dataList.deptList"
                      :key="item.deptId"
                      :label="item.deptName"
                      :value="item.deptId" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="整改人" prop="solvePersonal" :rules="dialog.form.status == 'YES' ? rules.solvePersonal : [{required: false}]">
                  <select-table
                    ref="solvePersonal"
                    v-model="dialog.form.solvePersonal"
                    :filter-form="selectTableModelSolvePerson.filterForm"
                    :filter-data="selectTableModelSolvePerson.filterData"
                    :default-data="dataList.dealStaffList"
                    :columns="selectTableModelSolvePerson.columns"
                    :total="selectTableModelSolvePerson.total"
                    :filter-fn="selectTableModelSolvePerson.filterFn"
                    @current-change="changeTableItemSolvePerson"
                    @clear="dialog.form.solvePersonal='';dialog.form.solvePersonalId=''" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="确认人" prop="confirmPersonal" :rules="dialog.form.status == 'YES' ? rules.confirmPersonal : [{required: false}]">
                  <select-table
                    ref="confirmPersonal"
                    v-model="dialog.form.confirmPersonal"
                    :filter-form="selectTableModelconfirmPersonal.filterForm"
                    :filter-data="selectTableModelconfirmPersonal.filterData"
                    :default-data="dataList.staffList"
                    :columns="selectTableModelconfirmPersonal.columns"
                    :total="selectTableModelconfirmPersonal.total"
                    :filter-fn="selectTableModelconfirmPersonal.filterFn"
                    @current-change="changeTableItemConfirmPersonal"
                    @clear="dialog.form.confirmPersonal='';dialog.form.solvePersonalId=''" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="整改措施" prop="solveMethod" :rules="dialog.form.status == 'YES' ? rules.solveMethod : [{required: false}]">
                  <el-input v-model="dialog.form.solveMethod" type="textarea" :autosize="{ minRows: 4}" maxlength="500" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="整改照片" prop="rectifImagesList" :rules="dialog.form.status == 'YES' ? rules.rectifImagesList : [{required: false}]">
                  <upload-file :model="fileModalRectifImages" @on-success="uploadSuccessRectifImages" />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset v-if="dialog.type == 'examine'">
            <legend>审核情况</legend>
            <el-row>
              <el-col :span="24">
                <el-form-item label="审核意见" prop="auidtOpinion">
                  <el-input v-model="dialog.form.auidtOpinion" type="textarea" :autosize="{ minRows: 4}" maxlength="500" />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
        </el-form>
        <!-- </el-scrollbar> -->
      </div>
      <div v-if="dialog.type == 'examine'" slot="footer" class="base-dialog__footer">
        <el-button
          type="primary"
          @click="updateData(3, 'YES')">
          通过
        </el-button>
        <el-button @click="updateData(3, 'NO')">
          驳回
        </el-button>
      </div>
      <div v-else slot="footer" class="base-dialog__footer">
        <el-button
          v-if="dialog.type === 'add' || dialog.form.defectStatus === 0 || dialog.form.defectStatus === 2"
          type="primary"
          @click="updateData(1)">
          保存并继续
        </el-button>
        <el-button
          type="primary"
          @click="updateData(2)">
          送审
        </el-button>
        <el-button @click="dialog.visible = false">
          取消
        </el-button>
      </div>
    </base-dialog>
  </div>
</template>

<script>
import {
  getInfoByIdDevice,
  saveOrUpdateDevice,
  getDevClasss,
  getByParams,
  defectRectifAuditFailDevice,
  defectRectifAuditPassDevice
} from '@/api/jcwwtk/information'
import { findWorkDeptList, getStaffList, getSeclineTree, getLineSiteList, getTunnelList } from '@/api/basic-data/common'
import { getListPage as getPillarList } from '@/api/catenary/pillar'
import { getListPage as getClassifyList } from '@/api/jcwwtk/classify'
import { getListPage as getGradeList } from '@/api/jcwwtk/grade'
import { getListPage as getPositionList } from '@/api/jcwwtk/position'
import { getListPage as getSourceList } from '@/api/jcwwtk/source'
// import { getDatatime } from '@/utils'
// import UploadFile from '@/views/jcwsc/components/UploadFile'

export default {
  components: {
    // UploadFile
  },
  props: {
    dialog: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    var checkRectifTime = (rule, value, cb) => {
      if (value && !this.dialog.form.rectifTimeUnit) {
        return cb(new Error('请选择单位'))
      } else {
        cb()
      }
    }
    return {
      loading: false,

      rules: {
        seclineId: { required: true, message: '请选择', trigger: 'change' },
        siteId: { required: true, message: '请选择', trigger: 'change' },
        pillarNum: { required: true, message: '请选择', trigger: 'change' },
        discoverPerson: { required: true, message: '请选择', trigger: 'change' },
        discoverSourceTypeId: { required: true, message: '请选择', trigger: 'change' },
        defectTypeName: { required: true, message: '请选择', trigger: 'change' },
        defectGradeName: { required: true, message: '请选择', trigger: 'change' },
        categoryName: { required: true, message: '请选择', trigger: 'change' },
        reasonName: { required: true, message: '请选择', trigger: 'change' },
        discoverDate: { required: true, message: '请选择', trigger: 'change' },
        rectifDatetime: { required: true, message: '请输入', trigger: 'blur' },
        solveWorkareaId: { required: true, message: '请选择', trigger: 'change' },
        defectInfoDesc: { required: true, message: '请输入', trigger: 'blur' },
        status: { required: true, message: '请选择', trigger: 'change' },
        solveDatetime: { required: true, message: '请选择', trigger: 'change' },
        handleWorkareaId: { required: true, message: '请选择', trigger: 'change' },
        solvePersonal: { required: true, message: '请选择', trigger: 'change' },
        confirmPersonal: { required: true, message: '请选择', trigger: 'change' },
        solveMethod: { required: true, message: '请输入', trigger: 'blur' },
        auidtOpinion: { required: true, message: '请输入', trigger: 'blur' },
        rectifTime: [
          { required: true, message: '请输入', trigger: 'blur' },
          { pattern: /^\d{1,}$/, message: '请输入整数' },
          { validator: checkRectifTime, trigger: 'blur' }
        ],
        duplicateBuildingNum: [
          { pattern: /^\d{1,}$/, message: '请输入整数', trigger: 'blur' }
        ],
        inlandForest: [
          { pattern: /^\d{1,}$/, message: '请输入整数', trigger: 'blur' }
        ],
        extraterrestrialForest: [
          { pattern: /^\d{1,}$/, message: '请输入整数', trigger: 'blur' }
        ],
        treeHeight: [
          { pattern: /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/, message: '请输入大于0数字', trigger: 'blur' }
        ],
        treeDiameter: [
          { pattern: /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/, message: '请输入大于0数字', trigger: 'blur' }
        ],
        // pillarImagesList: { required: true, message: '请上传杆号照片' },
        defectImagesList: { required: true, message: '请上传缺陷照片' },
        rectifImagesList: { required: true, message: '请上传整改照片' }
      },

      // 下拉框信息列表
      dataList: {
        deptList: [],
        siteList: [],
        pillarList: [],
        staffList: [],
        dealStaffList: [],
        seclineList: [],
        devClasssList: [],
        classifyList: [],
        gradeList: [],
        positionList: [],
        sourceList: [],
        rectifTimeUnitList: [], // 接触网问题库整改周期单位(天、月、日)
        treeTypeList: [], // 接触网树木问题库影响树木类型
        dangeTreeList: [], // 接触网树木问题库危树位置
        endangerDeviceList: [], // 接触网树木问题库可能危及设备
        distanceDeviceList: [] // 距离带电设备距离枚举
      },

      // 图片上传-杆号照片
      // fileModalPillarImages: {
      //   title: '',
      //   visible: false,
      //   pathList: [],
      //   fileList: [],
      //   type: 1,
      //   bizType: '1',
      //   key: 0,
      //   index: 0,
      //   isDetail: false,
      //   uploadType: 'img'
      // },

      // 图片上传-缺陷照片
      fileModalDefectImages: {
        title: '',
        visible: false,
        pathList: [],
        fileList: [],
        type: 1,
        bizType: '1',
        key: 0,
        index: 0,
        isDetail: false,
        uploadType: 'img'
      },

      // 图片上传-整改照片
      fileModalRectifImages: {
        title: '',
        visible: false,
        pathList: [],
        fileList: [],
        type: 1,
        bizType: '1',
        key: 0,
        index: 0,
        isDetail: false,
        uploadType: 'img'
      },

      // 时间选择器配置
      oneDayMsec: 1 * 24 * 3600 * 1000, // 一天的毫秒数
      pickerHandleDate: this.handleDate(),
      pickerSolveDate: this.handleDate(),
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > new Date().getTime()
        }
      },

      // 支柱选择器配置
      selectTableModel: {
        filterForm: {
          page: 1,
          size: 10,
          seclineId: '',
          siteId: '',
          pillarNum: '',
          directionId: '',
          tunnelId: '',
          unitCodeParams: ''
        },
        filterData: {
          pillarNum: {
            key: 'pillarNum',
            type: 'input',
            placeholder: '支柱号'
          },
          directionId: {
            width: '160px',
            key: 'directionId',
            type: 'select',
            title: '行别',
            placeholder: '行别',
            options: [],
            props: {
              label: 'directionName',
              value: 'directionId'
            },
            changeFn: () => {
              this.$refs.pillarNum.$refs.customSelect.focus()
            }
          },
          tunnelId: {
            width: '160px',
            key: 'tunnelId',
            type: 'select',
            title: '隧道',
            placeholder: '隧道',
            options: [],
            props: { label: 'tunnelName', value: 'tunnelId' },
            changeFn: () => {
              this.$refs.pillarNum.$refs.customSelect.focus()
            }
          }
        },
        columns: [
          { property: 'pillarNum', label: '支柱号' },
          { label: '公里标', prop: 'roadMark', formatter: row => this.formatRoad(row.roadMark) },
          { property: 'directionName', label: '行别' },
          { property: 'deptName', label: '所属工区' }
        ],
        total: 0,
        filterFn: getPillarList
      },

      // 发现人下拉配置
      selectTableModelFindBy: {
        filterForm: {
          page: 1,
          size: 10,
          staffName: '',
          deptId: '',
          unitCodeParams: ''
        },
        filterData: {
          staffName: {
            key: 'staffName',
            type: 'input',
            placeholder: '姓名'
          }
          // deptId: {
          //   clearable: false,
          //   key: 'deptId',
          //   type: 'selectTree',
          //   title: '部门',
          //   placeholder: '请选择部门',
          //   options: [],
          //   props: {
          //     label: 'label',
          //     value: 'id',
          //     parent: 'parentId',
          //     children: 'children'
          //   },
          //   changeFn: _ => {
          //     this.$refs.discoverPerson.$refs.customSelect.focus()
          //   }
          // }
        },
        columns: [
          { prop: 'staffName', label: '发现人' },
          { prop: 'deptName', label: '所属部门' }
        ],
        total: 0,
        filterFn: getStaffList
      },

      // 缺陷分类下拉配置
      selectTableModelClassify: {
        filterForm: {
          page: 1,
          size: 10,
          keyWord: '',
          unitCodeParams: ''
        },
        filterData: {
          keyWord: {
            key: 'keyWord',
            type: 'input',
            placeholder: '名称'
          }
        },
        columns: [
          { property: 'namePath', label: '分类名称' },
          { property: 'defectGradeName', label: '缺陷等级' }
        ],
        total: 0,
        filterFn: getClassifyList
      },

      // 缺陷等级下拉配置
      selectTableModelGrade: {
        filterForm: {
          page: 1,
          size: 10,
          keyWord: '',
          unitCodeParams: ''
        },
        filterData: {
          keyWord: {
            key: 'keyWord',
            type: 'input',
            placeholder: '名称'
          }
        },
        columns: [
          { property: 'defectGradeName', label: '等级名称' },
          { property: 'solveDays', label: '整改期限' },
          { property: 'remindTimeCount', label: '提醒期限' }
        ],
        total: 0,
        filterFn: getGradeList
      },

      // 缺陷部位下拉配置
      selectTableModelPosition: {
        filterForm: {
          page: 1,
          size: 10,
          keyWord: '',
          unitCodeParams: ''
        },
        filterData: {
          keyWord: {
            key: 'keyWord',
            type: 'input',
            placeholder: '名称'
          }
        },
        columns: [
          { property: 'namePath', label: '部位名称' }
        ],
        total: 0,
        filterFn: getPositionList
      },

      // 处理人下拉配置
      selectTableModelSolvePerson: {
        filterForm: {
          page: 1,
          size: 10,
          staffName: '',
          deptId: '',
          unitCodeParams: '',
          filterJcwFlag: 1 // 1只过滤接触网工区
        },
        filterData: {
          staffName: {
            key: 'staffName',
            type: 'input',
            placeholder: '姓名'
          }
          // deptId: {
          //   clearable: false,
          //   key: 'deptId',
          //   type: 'selectTree',
          //   title: '部门',
          //   placeholder: '请选择部门',
          //   options: [],
          //   props: {
          //     label: 'label',
          //     value: 'id',
          //     parent: 'parentId',
          //     children: 'children'
          //   },
          //   changeFn: _ => {
          //     this.$refs.discoverPerson.$refs.customSelect.focus()
          //   }
          // }
        },
        columns: [
          { property: 'staffName', label: '整改人' },
          { property: 'deptName', label: '所属部门' }
        ],
        total: 0,
        filterFn: getStaffList
      },

      // 确认人
      selectTableModelconfirmPersonal: {
        filterForm: {
          page: 1,
          size: 10,
          staffName: '',
          deptId: '',
          unitCodeParams: ''
        },
        filterData: {
          staffName: {
            key: 'staffName',
            type: 'input',
            placeholder: '姓名'
          }
          // deptId: {
          //   clearable: false,
          //   key: 'deptId',
          //   type: 'selectTree',
          //   title: '部门',
          //   placeholder: '请选择部门',
          //   options: [],
          //   props: {
          //     label: 'label',
          //     value: 'id',
          //     parent: 'parentId',
          //     children: 'children'
          //   },
          //   changeFn: _ => {
          //     this.$refs.discoverPerson.$refs.customSelect.focus()
          //   }
          // }
        },
        columns: [
          { property: 'staffName', label: '发现人' },
          { property: 'deptName', label: '所属部门' }
        ],
        total: 0,
        filterFn: getStaffList
      }
    }
  },
  watch: {
    'dialog.visible'() {
      if (this.dialog.visible) {
        this.selectTableModelFindBy.filterForm.unitCodeParams = this.dialog.form.unitCodeParams
        this.selectTableModelSolvePerson.filterForm.unitCodeParams = this.dialog.form.unitCodeParams
        this.selectTableModelconfirmPersonal.filterForm.unitCodeParams = this.dialog.form.unitCodeParams
        this.selectTableModelClassify.filterForm.unitCodeParams = this.dialog.form.unitCodeParams
        this.selectTableModelGrade.filterForm.unitCodeParams = this.dialog.form.unitCodeParams
        this.selectTableModelPosition.filterForm.unitCodeParams = this.dialog.form.unitCodeParams
        this.dialog.form = {
          defectInfoId: this.dialog.form.id,
          seclineId: '',
          siteId: '',
          pillarId: '',
          pillarNum: '',
          discoverPersonId: '',
          discoverPersonList: [],
          discoverPerson: '',
          discoverSourceTypeId: '',
          defectTypeId: '',
          defectTypeName: '',
          defectGradeId: '',
          defectGradeName: '',
          defectPositionId: '',
          positionName: '',
          discoverDate: '',
          rectifDatetime: '',
          solveWorkareaId: '',
          defectInfoDesc: '',
          handleWorkareaId: '',
          solvePersonal: '',
          confirmPersonal: '',
          distanceDevice: '',
          rectifTimeUnit: '',
          pillarImagesList: [],
          defectImagesList: [],
          rectifImagesList: [],
          unitCodeParams: this.dialog.form.unitCodeParams,
          defectStatus: this.dialog.form.defectStatus,
          inputAuditStatus: this.dialog.form.inputAuditStatus
        }
        this.fileModalPillarImages.fileList = []
        this.fileModalPillarImages.pathList = []
        this.fileModalDefectImages.fileList = []
        this.fileModalDefectImages.pathList = []
        this.fileModalRectifImages.fileList = []
        this.fileModalRectifImages.pathList = []
        // 获取下拉数据、字典
        this.getList().then(() => {
          // if：编辑
          if (this.dialog.type === 'edit' || this.dialog.type === 'examine') {
            this.getInfoById(this.dialog.form.defectInfoId) // 根据id查询信息
          }
        })
        this.$nextTick(() => {
          this.$refs.dataForm.clearValidate()
        })
      } else {
        this.dataList.siteList = []
        this.dataList.pillarList = []
      }
    }
  },
  methods: {
    // 切换顶部缺陷种类
    changeDefectType(e) {
      // 控制滚动到最新消息
      var div = this.$refs['scrollbarData'].$refs['wrap']
      this.$nextTick(() => {
        div.scrollTop = 0
        this.$refs.dataForm.clearValidate()
      })
    },

    // 选择整改期限单位
    changeRectifTimeUnit(item) {
      this.dialog.form.rectifTimeUnit = item
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate('rectifTime')
      })
    },

    // 选择确认人
    changeTableItemConfirmPersonal(row) {
      this.dialog.form.confirmPersonalId = row.staffId
      this.dialog.form.confirmPersonal = row.staffName
    },

    // 选择整改人
    changeTableItemSolvePerson(row) {
      this.dialog.form.solvePersonalId = row.staffId
      this.dialog.form.solvePersonal = row.staffName
      this.dialog.form.handleWorkareaId = row.deptId
      this.dialog.form.handleWorkareaName = row.deptName
    },

    // 获取下拉数据、字典
    getList() {
      return new Promise((resolve) => {
        // 获取接触网工区
        findWorkDeptList({ unitCodeParams: this.dialog.form.unitCodeParams }).then(response => {
          this.dataList.deptList = response.data
          resolve()
        })
        // 查询线路树信息列表
        getSeclineTree({ unitCodeParams: this.dialog.form.unitCodeParams }).then(response => {
          this.dataList.seclineList = response.data
          resolve()
        })
        // 查询设备类型
        getDevClasss({ unitCodeParams: this.dialog.form.unitCodeParams, isPage: 1 }).then(response => {
          this.dataList.devClasssList = response.data
        })
        // 查询人员信息列表
        getStaffList(this.selectTableModelFindBy.filterForm).then((response) => {
          this.dataList.staffList = response.data.records
          this.selectTableModelFindBy.total = response.data.total
          this.$nextTick(() => {
            this.$refs.dataForm.clearValidate()
          })
          resolve()
        })
        // 查询人员信息列表
        getStaffList(this.selectTableModelSolvePerson.filterForm).then((response) => {
          this.dataList.dealStaffList = response.data.records
          this.selectTableModelSolvePerson.total = response.data.total
          this.selectTableModelconfirmPersonal.total = response.data.total
          this.$nextTick(() => {
            this.$refs.dataForm.clearValidate()
          })
          resolve()
        })
        // 查询缺陷分类列表
        getClassifyList(this.selectTableModelClassify.filterForm).then((response) => {
          this.dataList.classifyList = response.data.records
          this.selectTableModelClassify.total = response.data.total
          resolve()
        })
        // 查询缺陷等级列表
        getGradeList(this.selectTableModelGrade.filterForm).then((response) => {
          this.dataList.gradeList = response.data.records
          this.selectTableModelGrade.total = response.data.total
          resolve()
        })
        // 查询缺陷部位列表
        getPositionList(this.selectTableModelPosition.filterForm).then((response) => {
          this.dataList.positionList = response.data.records
          this.selectTableModelPosition.total = response.data.total
          resolve()
        })
        // 查询缺陷来源列表
        getSourceList({ unitCodeParams: this.unitCodeParams }).then((response) => {
          this.dialog.dataList.sourceList = response.data.records
        })

        // 接触网问题库整改周期单位(天、月、日)
        getByParams({ unitCodeParams: this.unitCodeParams, dtId: 'JCW_DEFECT_UNIT' }).then((response) => {
          if (response.data && response.data.length) {
            this.dataList.rectifTimeUnitList = response.data
            this.dataList.rectifTimeUnitList.forEach(val => {
              if (val.itemName === '月') {
                this.dialog.form.rectifTimeUnit = val.dictionaryId
              }
            })
            this.$nextTick(() => {
              this.$refs.dataForm.clearValidate('rectifTime')
            })
          }
        })

        // 接触网树木问题库影响树木类型
        getByParams({ unitCodeParams: this.unitCodeParams, dtId: 'JCW_TREE_TYPE' }).then((response) => {
          if (response.data && response.data.length) {
            this.dataList.treeTypeList = response.data
          }
        })

        // 接触网树木问题库危树位置
        getByParams({ unitCodeParams: this.unitCodeParams, dtId: 'JCW_DANGE_TREE' }).then((response) => {
          if (response.data && response.data.length) {
            this.dataList.dangeTreeList = response.data
          }
        })

        // 接触网树木问题库可能危及设备
        getByParams({ unitCodeParams: this.unitCodeParams, dtId: 'JCW_ENDANGER_DEVICE' }).then((response) => {
          if (response.data && response.data.length) {
            this.dataList.endangerDeviceList = response.data
          }
        })

        // 距离带电设备距离枚举
        getByParams({ unitCodeParams: this.unitCodeParams, dtId: 'JCW_DISTANCE_DEVICE' }).then((response) => {
          if (response.data && response.data.length) {
            this.dataList.distanceDeviceList = response.data
          }
        })
      })
    },

    // 根据id查询信息
    getInfoById(id) {
      this.loading = true
      // 根据id查询设备信息
      getInfoByIdDevice({
        unitCodeParams: this.dialog.form.unitCodeParams,
        id: id
      }).then(response => {
        const unitCodeParams = this.dialog.form.unitCodeParams
        this.dialog.form = response.data
        this.dialog.form.unitCodeParams = unitCodeParams

        if (this.dialog.form.inputAuditStatus === 2) {
          this.dialog.form.status = 'YES'
          this.fileModalPillarImages.isDetail = true
          this.fileModalDefectImages.isDetail = true
        } else {
          this.fileModalPillarImages.isDetail = false
          this.fileModalDefectImages.isDetail = false
        }

        // 组装dialog.form.pillarImagesList
        this.dialog.form.pillarImagesList.forEach(val => {
          const data = {
            name: val.fileName,
            fileSize: val.fileSize,
            fileExtname: val.fileExtname,
            fileName: val.fileName,
            filePath: val.filePath,
            thumbnail: val.thumbnail,
            fileType: val.fileExtname,
            memo: val.memo,
            uploadType: val.uploadType,
            url: val.url
          }
          this.fileModalPillarImages.fileList.push(data)
          this.fileModalPillarImages.pathList.push(data.filePath)
        })

        // 组装dialog.form.defectImagesList
        this.dialog.form.defectImagesList.forEach(val => {
          const data = {
            name: val.fileName,
            fileSize: val.fileSize,
            fileExtname: val.fileExtname,
            fileName: val.fileName,
            filePath: val.filePath,
            thumbnail: val.thumbnail,
            fileType: val.fileExtname,
            memo: val.memo,
            uploadType: val.uploadType,
            url: val.url
          }
          this.fileModalDefectImages.fileList.push(data)
          this.fileModalDefectImages.pathList.push(data.filePath)
        })

        // 组装dialog.form.rectifImagesList
        this.dialog.form.rectifImagesList.forEach(val => {
          const data = {
            name: val.fileName,
            fileSize: val.fileSize,
            fileExtname: val.fileExtname,
            fileName: val.fileName,
            filePath: val.filePath,
            thumbnail: val.thumbnail,
            fileType: val.fileExtname,
            memo: val.memo,
            uploadType: val.uploadType,
            url: val.url
          }
          this.fileModalRectifImages.fileList.push(data)
          this.fileModalRectifImages.pathList.push(data.filePath)
        })

        // 组装人员信息
        this.dialog.form.discoverPersonList = []
        this.dialog.form.discoverPersonIdList = []
        if (this.dialog.form.discoverPerson.indexOf(',') !== -1 && this.dialog.form.discoverPersonId.indexOf(',') !== -1) {
          this.dialog.form.discoverPersonId.split(',').forEach((val, key) => {
            this.dialog.form.discoverPersonList.push({
              staffId: val,
              staffName: this.dialog.form.discoverPerson.split(',')[key]
            })
            this.dialog.form.discoverPersonIdList.push(val)
          })
        } else {
          if (this.dialog.form.discoverPerson !== '' && this.dialog.form.discoverPersonId !== '') {
            this.dialog.form.discoverPersonList = [{ staffId: this.dialog.form.discoverPersonId, staffName: this.dialog.form.discoverPerson }]
            this.dialog.form.discoverPersonIdList = [this.dialog.form.discoverPersonId]
          }
        }

        // 处理选择框匹配不到回显id问题
        if (this.dialog.form.seclineId) {
          const data = this.getChidlren(this.dialog.form.seclineId, this.dataList.seclineList)
          if (data.length !== 0) {
            this.dialog.form.seclineId = data[0].id
          } else {
            this.dialog.form.seclineId = ''
          }
        }
        if (this.dialog.form.discoverSourceTypeId) {
          let dealId = ''
          this.dialog.dataList.sourceList.forEach(val => {
            if (this.dialog.form.discoverSourceTypeId === val.sourceTypeId) {
              dealId = val.sourceTypeId
            }
          })
          this.dialog.form.discoverSourceTypeId = dealId
        }
        if (this.dialog.form.solveWorkareaId) {
          let dealId = ''
          this.dataList.deptList.forEach(val => {
            if (this.dialog.form.solveWorkareaId === val.deptId) {
              dealId = val.deptId
            }
          })
          this.dialog.form.solveWorkareaId = dealId
        }

        if (this.dialog.form.seclineId) {
          this.getSiteList() // 查询区间站场信息列表
          if (this.dialog.form.siteId) {
            this.getPillarList() // 查询支柱号信息列表
          }
        }

        this.$nextTick(() => {
          this.$refs.dataForm.clearValidate()
        })
        this.loading = false
      }).catch(_ => {
        this.loading = false
      })
    },

    // 查找树结构
    getChidlren(id, data) {
      // 根据ID进行树过滤
      var hasFound = false // 表示是否有找到id值
      var result = null
      var fn = function(data) {
        if (Array.isArray(data) && !hasFound) {
          // 判断是否是数组并且没有的情况下，
          data.forEach((item) => {
            if (item.id === id) {
              // 数据循环每个子项，并且判断子项下边是否有id值
              result = item // 返回的结果等于每一项
              hasFound = true // 并且找到id值
            } else if (item.children) {
              fn(item.children) // 递归调用下边的子项
            }
          })
        }
      }
      fn(data) // 调用一下
      return [result]
    },

    // 查询区间站场信息列表
    getSiteList() {
      // 查询区间站场信息列表
      getLineSiteList({
        unitCodeParams: this.dialog.form.unitCodeParams,
        seclineId: this.dialog.form.seclineId
      }).then(response => {
        this.dataList.siteList = response.data

        // 处理选择框匹配不到回显id问题
        if (this.dialog.form.siteId) {
          let dealId = ''
          this.dataList.siteList.forEach(val => {
            if (this.dialog.form.siteId === val.siteId) {
              dealId = val.siteId
            }
          })
          this.dialog.form.siteId = dealId
        }
      })
    },

    // 查询隧道信息列表
    getTunnelList(siteId) {
      // 查询隧道信息列表
      getTunnelList({
        unitCodeParams: this.dialog.form.unitCodeParams,
        siteId: siteId
      }).then(response => {
        this.selectTableModel.filterData.tunnelId.options = response.data
      })
    },

    // 查询支柱号信息列表
    getPillarList() {
      this.dataList.pillarList = []
      this.selectTableModel.filterForm = {
        page: 1,
        size: 10,
        seclineId: this.dialog.form.seclineId,
        siteId: this.dialog.form.siteId,
        pillarNum: '',
        directionId: '',
        unitCodeParams: this.dialog.form.unitCodeParams
      }
      this.selectTableModel.filterData.directionId.options = this.dialog.dataList.directionList
      // 查询支柱号信息列表
      getPillarList(this.selectTableModel.filterForm).then(response => {
        this.dataList.pillarList = response.data.records
        this.selectTableModel.total = response.data.total
      })
    },

    // 选择线路
    changeSeclineId(seclineId) {
      this.dialog.form.siteId = ''
      this.dataList.siteList = []
      this.dialog.form.pillarId = ''
      this.dialog.form.pillarNum = ''
      this.dataList.pillarList = []
      this.dialog.form.solveWorkareaId = ''
      if (seclineId !== '') {
        this.getSiteList() // 查询区间站场信息列表
      }
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate('seclineId')
        this.$refs.dataForm.clearValidate('siteId')
        this.$refs.dataForm.clearValidate('pillarNum')
        this.$refs.dataForm.clearValidate('solveWorkareaId')
      })
    },

    // 选择区间站场
    changeSiteId(siteId) {
      this.dialog.form.pillarId = ''
      this.dialog.form.pillarNum = ''
      this.dataList.pillarList = []
      this.dialog.form.solveWorkareaId = ''
      this.selectTableModel.filterData.tunnelId.options = []
      if (siteId !== '') {
        this.getTunnelList(siteId) // 查询隧道信息列表
        this.getPillarList() // 查询支柱号信息列表
      }
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate('siteId')
        this.$refs.dataForm.clearValidate('pillarNum')
        this.$refs.dataForm.clearValidate('solveWorkareaId')
      })
    },

    // 选择支柱
    changePillarId(item) {
      this.dialog.form.pillarId = item.pillarId
      this.dialog.form.pillarNum = item.pillarNum
      this.dialog.form.pillarDeptId = item.deptId
      this.dialog.form.solveWorkareaId = item.deptId
      // this.dialog.form.handleWorkareaId = item.handleWorkareaId
      this.dialog.form.roadMark = item.roadMark
      this.dialog.form.directionName = item.directionName
      this.dialog.form.trackName = item.trackName ? item.trackName : '非股道'
      this.dialog.form.tunnelName = item.tunnelName ? item.tunnelName : '非隧道'
      this.dialog.form.pillarDeptName = item.deptName
      if (this.dialog.form.solveWorkareaId) {
        let dealId = ''
        this.dataList.deptList.forEach(val => {
          if (this.dialog.form.solveWorkareaId === val.deptId) {
            dealId = val.deptId
          }
        })
        this.dialog.form.solveWorkareaId = dealId
      }
    },

    // 支柱清除
    clearPillarId() {
      this.dialog.form.pillarId = ''
      this.dialog.form.pillarNum = ''
      this.dialog.form.pillarDeptId = ''
      this.dialog.form.solveWorkareaId = ''
      // this.dialog.form.handleWorkareaId = '
      this.dialog.form.roadMark = ''
      this.dialog.form.directionName = ''
      this.dialog.form.trackName = ''
      this.dialog.form.tunnelName = ''
      this.dialog.form.pillarDeptName = ''
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate('pillarNum')
        this.$refs.dataForm.clearValidate('solveWorkareaId')
      })
    },

    // 选择发现人
    changeTableItemFindBy(data) {
      this.dialog.form.discoverPersonList = []
      this.dialog.form.discoverPerson = ''
      data.forEach(val => {
        this.dialog.form.discoverPersonList.push({
          staffId: val.staffId,
          staffName: val.staffName
        })
        this.dialog.form.discoverPerson += val.staffName + ','
      })
      if (this.dialog.form.discoverPerson.indexOf(',') !== -1) {
        this.dialog.form.discoverPerson = this.dialog.form.discoverPerson.substring(0, this.dialog.form.discoverPerson.length - 1)
      }
      this.dialog.form.discoverPersonIdList = []
      this.dialog.form.discoverPersonId = ''
      this.dialog.form.findDeptId = ''
      data.forEach(val => {
        this.dialog.form.discoverPersonIdList.push(val.staffId)
        this.dialog.form.discoverPersonId += val.staffId + ','
        this.dialog.form.findDeptId += val.deptId + ','
      })
      if (this.dialog.form.discoverPersonId.indexOf(',') !== -1) {
        this.dialog.form.discoverPersonId = this.dialog.form.discoverPersonId.substring(0, this.dialog.form.discoverPersonId.length - 1)
        this.dialog.form.findDeptId = this.dialog.form.findDeptId.substring(0, this.dialog.form.findDeptId.length - 1)
      }
      // this.dialog.form.discoverPersonId = row.staffId
      // this.dialog.form.discoverPerson = row.staffName
      // this.dialog.form.findDeptId = row.deptId
    },

    // 选择缺陷分类
    changeTableItemDefectType(row) {
      this.dialog.form.defectTypeId = row.defectTypeId
      this.dialog.form.defectTypeName = row.defectTypeName
      this.dialog.form.defectGradeId = row.defectGradeId
      this.dialog.form.defectGradeName = row.defectGradeName
      // const currentLevel = this.dataList.gradeList.find(item => item.defectGradeId === row.defectGradeId)
      // if (currentLevel) {
      //   const rectifDatetime = getDatatime(new Date(new Date(this.dialog.form.discoverDate).getTime() + (currentLevel.solveDays * 86400000)))
      //   this.dialog.form.rectifDatetime = this.dialog.form.discoverDate && currentLevel && currentLevel.solveDays ? rectifDatetime.substring(0, 10) : ''
      // }
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate('defectGradeName')
        // this.$refs.dataForm.clearValidate('rectifDatetime')
      })
    },

    // 选择缺陷等级
    changeTableItemGrade(row) {
      this.dialog.form.defectGradeId = row.defectGradeId
      this.dialog.form.defectGradeName = row.defectGradeName
    },

    // 选择缺陷部位
    changeTableItemPosition(row) {
      this.dialog.form.defectPositionId = row.defectPositionId
      this.dialog.form.positionName = row.positionName
    },

    // 选择发现日期
    changeFindDate() {
      if (this.dialog.form.defectGradeId !== '') {
        // const currentLevel = this.dataList.gradeList.find(item => item.defectGradeId === this.dialog.form.defectGradeId)
        // const rectifDatetime = getDatatime(new Date(new Date(this.dialog.form.discoverDate).getTime() + (currentLevel.solveDays * 86400000)))
        // this.dialog.form.rectifDatetime = this.dialog.form.discoverDate && currentLevel && currentLevel.solveDays ? rectifDatetime.substring(0, 10) : ''
      }
    },

    // 整改图片上传成功
    uploadSuccessRectifImages(filelist, type, key, index, fileArr) {
      this.dialog.form.rectifImagesList = []
      fileArr.forEach(val => {
        const data = {
          name: val.fileName,
          fileSize: val.fielSize,
          fileExtname: val.fileExtname,
          fileName: val.fileName,
          filePath: val.filePath,
          thumbnail: val.thumbnail,
          fileType: val.fileExtname,
          uploadType: val.uploadType,
          memo: ''
        }
        this.dialog.form.rectifImagesList.push(data)
      })
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate('rectifImagesList')
      })
      this.notifiySuccess('上传成功')
    },

    // 缺陷照片上传成功
    uploadSuccessDefectImages(filelist, type, key, index, fileArr) {
      this.dialog.form.defectImagesList = []
      fileArr.forEach(val => {
        const data = {
          name: val.fileName,
          fileSize: val.fielSize,
          fileExtname: val.fileExtname,
          fileName: val.fileName,
          filePath: val.filePath,
          thumbnail: val.thumbnail,
          fileType: val.fileExtname,
          uploadType: val.uploadType,
          memo: ''
        }
        this.dialog.form.defectImagesList.push(data)
      })
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate('defectImagesList')
      })
      this.notifiySuccess('上传成功')
    },

    // 杆号照片上传成功
    uploadSuccessPillarImages(filelist, type, key, index, fileArr) {
      this.dialog.form.pillarImagesList = []
      fileArr.forEach(val => {
        const data = {
          name: val.fileName,
          fileSize: val.fielSize,
          fileExtname: val.fileExtname,
          fileName: val.fileName,
          filePath: val.filePath,
          thumbnail: val.thumbnail,
          fileType: val.fileExtname,
          uploadType: val.uploadType,
          memo: ''
        }
        this.dialog.form.pillarImagesList.push(data)
      })
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate('pillarImagesList')
      })
      this.notifiySuccess('上传成功')
    },

    // 整改期限、处理日期控制
    handleDate() {
      const self = this
      return {
        disabledDate(time) {
          if (self.dialog.form.discoverDate) { // 如果发现时间不为空，则大于发现时间大于等于当天
            var time1 = new Date(self.dialog.form.discoverDate).getTime() - 8.64e7 // 发现日期时间戳
            const a = time.getTime() > Date.now()
            return a || time.getTime() <= time1
            // return time.getTime() > Date.now() // 发现时间不选时，整改期限时间最大值大于等于当天
          }
        }
      }
    },

    // 审核通过
    defectRectifAuditPassDevice() {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          this.dialog.loading = true
          // 杆号照片
          this.dialog.form.pillarImagesList.forEach(val => {
            val.photoFlag = 5
            if (val.fileExtname.indexOf('.') === -1) {
              val.fileExtname = '.' + val.fileExtname
            }
            if (val.fileType.indexOf('.') === -1) {
              val.fileType = '.' + val.fileType
            }
          })
          // 缺陷照片
          this.dialog.form.defectImagesList.forEach(val => {
            val.photoFlag = 1
            if (val.fileExtname.indexOf('.') === -1) {
              val.fileExtname = '.' + val.fileExtname
            }
            if (val.fileType.indexOf('.') === -1) {
              val.fileType = '.' + val.fileType
            }
          })
          // 整改照片
          this.dialog.form.rectifImagesList.forEach(val => {
            val.photoFlag = 2
            if (val.fileExtname.indexOf('.') === -1) {
              val.fileExtname = '.' + val.fileExtname
            }
            if (val.fileType.indexOf('.') === -1) {
              val.fileType = '.' + val.fileType
            }
          })
          // 新增/修改信息
          // inputAuditStatus 缺陷录入审核状态（0：未审核 1：审核中 2：已审核通过）
          // rectifAuditStatus 缺陷整改审核状态（0：未审核 1：审核中 2：已审核通过）
          defectRectifAuditPassDevice(this.dialog.form).then(() => {
            this.notifiySuccess('操作成功')
            this.$emit('updateData')
          }).catch(() => {
            this.dialog.loading = false
          })
        }
      })
    },

    // 审核不通过
    defectRectifAuditFailDevice() {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          this.dialog.loading = true
          // 杆号照片
          this.dialog.form.pillarImagesList.forEach(val => {
            val.photoFlag = 5
            if (val.fileExtname.indexOf('.') === -1) {
              val.fileExtname = '.' + val.fileExtname
            }
            if (val.fileType.indexOf('.') === -1) {
              val.fileType = '.' + val.fileType
            }
          })
          // 缺陷照片
          this.dialog.form.defectImagesList.forEach(val => {
            val.photoFlag = 1
            if (val.fileExtname.indexOf('.') === -1) {
              val.fileExtname = '.' + val.fileExtname
            }
            if (val.fileType.indexOf('.') === -1) {
              val.fileType = '.' + val.fileType
            }
          })
          // 整改照片
          this.dialog.form.rectifImagesList.forEach(val => {
            val.photoFlag = 2
            if (val.fileExtname.indexOf('.') === -1) {
              val.fileExtname = '.' + val.fileExtname
            }
            if (val.fileType.indexOf('.') === -1) {
              val.fileType = '.' + val.fileType
            }
          })
          // 新增/修改信息
          // inputAuditStatus 缺陷录入审核状态（0：未审核 1：审核中 2：已审核通过）
          // rectifAuditStatus 缺陷整改审核状态（0：未审核 1：审核中 2：已审核通过）
          defectRectifAuditFailDevice(this.dialog.form).then(() => {
            this.notifiySuccess('操作成功')
            this.$emit('updateData')
          }).catch(() => {
            this.dialog.loading = false
          })
        }
      })
    },

    // 回调方法
    updateData(buttonType, skipFlag) {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          // 点击整改时
          if ((this.dialog.form.defectStatus === 2 || this.dialog.form.defectStatus === 7) && this.dialog.form.status === 'NO') {
            this.notifiyWarning('整改状态需为已整改，并填完信息后送审')
            return
          }
          this.dialog.loading = true
          if (this.dialog.form.status === 'NO') {
            this.dialog.form.solveDatetime = ''
            this.dialog.form.confirmPersonalId = ''
            this.dialog.form.confirmPersonal = ''
            this.dialog.form.solvePersonalId = ''
            this.dialog.form.solvePersonal = ''
            this.dialog.form.handleWorkareaId = ''
            this.dialog.form.handleWorkareaName = ''
            this.dialog.form.solveMethod = ''
            this.dialog.form.rectifImagesList = []
          }
          // 杆号照片
          if (this.dialog.form.pillarImagesList.length) {
            this.dialog.form.pillarImagesList.forEach(val => {
              val.photoFlag = 5
              if (val.fileExtname.indexOf('.') === -1) {
                val.fileExtname = '.' + val.fileExtname
              }
              if (val.fileType.indexOf('.') === -1) {
                val.fileType = '.' + val.fileType
              }
            })
          }
          // 缺陷照片
          if (this.dialog.form.defectImagesList.length) {
            this.dialog.form.defectImagesList.forEach(val => {
              val.photoFlag = 1
              if (val.fileExtname.indexOf('.') === -1) {
                val.fileExtname = '.' + val.fileExtname
              }
              if (val.fileType.indexOf('.') === -1) {
                val.fileType = '.' + val.fileType
              }
            })
          }
          // 整改照片
          if (this.dialog.form.rectifImagesList.length) {
            this.dialog.form.rectifImagesList.forEach(val => {
              val.photoFlag = 2
              if (val.fileExtname.indexOf('.') === -1) {
                val.fileExtname = '.' + val.fileExtname
              }
              if (val.fileType.indexOf('.') === -1) {
                val.fileType = '.' + val.fileType
              }
            })
          }
          if (buttonType === 3) {
            this.dialog.form.skipFlag = skipFlag
          }
          this.dialog.form.buttonType = buttonType
          saveOrUpdateDevice(this.dialog.form).then((response) => {
            this.notifiySuccess(buttonType === 1 ? '保存成功' : buttonType === 2 ? '送审成功' : '审核成功')
            if (buttonType === 1) {
              this.dialog.form.defectInfoId = response.data
              this.$emit('updateDataNoClose')
              this.$nextTick(() => {
                this.$refs.dataForm.clearValidate()
              })
            } else {
              this.$emit('updateData')
            }
          }).catch(() => {
            this.dialog.loading = false
          })
        }
      })
    },

    // 初始化
    beforeOpenDialog() {
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate()
      })
    }
  }
}
</script>
<style lang="scss" scoped>
  // .data-form-box {
  //   height: 588px;
  //   // .data-form-scrollbar {
  //   //   height: 100%;
  //     // ::v-deep .el-scrollbar__wrap {
  //     //   overflow-x: hidden;
  //   // .rectif-datetime {
  //   //   .el-select .el-input {
  //   //     width: 80px;
  //   //   }
  //   //   .el-input-group__prepend {
  //   //     background-color: #fff;
  //   //   }
  //   // }
  //     // }
  //   // }
  // }
  // .is-fullscreen {
  //   .data-form-box {
  //     height: 762px;
  //   }
  // }
  .rectif-datetime {
    ::v-deep .el-select .el-input {
      width: 80px;
    }
    ::v-deep .el-input-group__prepend {
      background-color: #fff;
    }
  }
</style>
